﻿// JScript 文件


var rownoArr = new Array();
var mc = null;
var tc = null;
var grlyobj = null;

function dispGrAtt(bm)
{
    var min = (m_GrType == 0) ? 145 : 852;
    top.ExecuteATool(top.m_vt.FUN_ATTBM,[95,min,bm,"edit",editGrAtt,"<items><bm>"+bm+"</bm></items>"]);

}

function editGrAtt(dlg)
{
     var xml = dlg.wnd.getXml();
     
     
     dlg.close();
}

function CreateTab()
{
    tc = new CtnTabCtrl("tc");
    tc.create("tabsB");
    
    tc.append("光路列表:", 0);
    tc.append("路由信息:", 1);
    tc.append("承载光缆:", 2);   
    
    
    tc.onTab = showTab;
    tc.setActive(0);
}


function showTab(iTab)
{

   $("butList").style.top = document.documentElement.clientHeight - 33;
   switch(iTab)
   {
       case 0:
             $("GrListCtr").show();
             $("GrLyCtr").hide();
             $("GlCtr").hide();
             $("GrLyMap").hide();
             $("butList").innerHTML = "<table width=\"99.8%\"><tr><td align=\"right\">"
                                        +"<input type=\"button\" class=\"button\" value=\"导出系统信息\"  onclick='GenerateExcel(0)'/>"
                                        +"<input type=\"button\" class=\"button\" value=\"导出电路信息\"  onclick='GenerateExcel(1)'/>"
                                        +"<input type=\"button\" class=\"button\" value=\"导出路由信息\"  onclick='GenerateExcel(2)'/>"
                                        +"</td></tr></table>";
             break;
       case 1:
             $("GrListCtr").hide();
             $("GrLyCtr").show();
             $("GlCtr").hide();
             $("GrLyMap").show();
             $("butList").innerHTML = "<table width=\"99.8%\"><tr><td align=\"right\">"
                                        +"<input type=\"button\" class=\"button\" value=\"导出路由信息\" onclick='GenerateExcel(2)'/>"
                                       
                                        +"</td></tr></table>";
             
             break;
       case 2:
             $("GrListCtr").hide();
             $("GrLyCtr").hide();
             $("GlCtr").show();
             $("GrLyMap").hide();
             $("butList").innerHTML = "<table width=\"99.8%\"><tr><td align=\"right\">"
                                        +"<input type=\"button\" class=\"button\" value=\"导出系统信息\"  onclick='GenerateExcel(0)'/>"
                                        +"<input type=\"button\" class=\"button\" value=\"导出电路信息\"  onclick='GenerateExcel(1)'/>"
                                        +"<input type=\"button\" class=\"button\" value=\"查看光路信息\"  onclick='GenerateExcel(3)'/>"
                                        +"</td></tr></table>";
             break;
       default:
             break;
             
   }
}
    document.onclick = function (evt)
    {
        if(mc)mc.hide();
    }

function onRowRClick_Gr(evt,rowno)
{

    var bm = listGr.getCell(rowno, 0).val;
    
    mc = new CtnMenuCtrl("mc");
    
   
    mc.addEvent("查看路由", "GetGrLy('"+bm+"')");
    mc.addEvent("查看光缆", "GetGl('"+bm+"')");
    mc.addEvent("<hr/>", "");
    mc.addEvent("调整光路", "ModifyGr('"+bm+"')");
    mc.addEvent("拆除光路", "DelGr('"+bm+"')");
    mc.addEvent("定位光路", "LocatGr('"+bm+"')");
    if(parseInt(m_GrType) == 1)
    {
        mc.addEvent("<< 光路逻辑图", "DispLoG('"+bm+"')");
    }
    
    mc.show(evt);
}

function LocatGr(bm)
{
   var min = (parseInt(m_GrType) == 1) ? 852 : 145;
   top.EntityLocatByBm(95,min,bm);
}

function onCheck_Gr(rowno,checked)
{
    var i = 0;
    for(i = 0; i < rownoArr.length; i++)
    {
       if(rownoArr[i] == rowno)
           break;
    }
    if(checked)
    {
       
       if(i == rownoArr.length)
           rownoArr.push(rowno);
    }
    else
    {
        if(i < rownoArr.length)
           rownoArr.splice(i,1);
    }
}

function onCheckToggle_Gr(checked)
{
    while(rownoArr.length > 0)
    {
        rownoArr.pop()
    }
    if(checked)
    {
        for(var i = 0; i < listGr.arrRow.length; i++)
        {
            rownoArr.push(i);
        }
    }
}

//查看光路属性信息

function GetGrAtt(bm)
{
    
}

//出逻辑图

function DispLoG(bm)
{
    top.ExecuteATool(top.m_vt.MAP_GRLYMAP,[bm,m_GrType,1]);   
}

//查看光路路由

function GetGrLy(bm)
{
    tc.setActive(1);
    listLy.create("GrLyCtr");
    
     var serverUrl = "_method=GetGrly"
                                   + "&GrBM=" + escape(bm)
                                   + "&IsHasGl=1"
                                   + "&GrType=" + m_GrType
                                   + "&IsGLy=1"
                                   + "&IsHasLogicMap=0";
                                  
     var vXml = top.CtnTrans.getText("/main.ashx?", "post", serverUrl)
     
     if (!CtnError.validate(vXml))
     {
        CtnError.show();
        return;
     }
     //显示图形信息
     var mapObj = $("GrLyMap")
     mapObj.style.top = document.documentElement.clientHeight - 100
     if(!grlyobj)
     {
          grlyobj =  new CtnGrLyMap({w:150,left:10,top:10,id:"GrLyMap",readonly:true,lay_h:"20"});
     }
     
     grlyobj.DrawByXml(vXml);
     //
     
     vXml = ConvertGraphToData_LY(vXml,bm)
     listLy.reset();
     listLy.insertXml(vXml, 1);
     
     listLy.show();
     
     
}

//查看光缆

function GetGl(bm)
{
    tc.setActive(2);
    var colcfg = GetQueCfg(1012);
    var GlcolInfo = "<?xml version='1.0' encoding='gb2312' ?><items>";
    for(var i = 0; i < colcfg.length; i++)
	{
	   
	     GlcolInfo += "<item><maj>" + colcfg[i].maj + "</maj>"
	          + "<min>" + colcfg[i].min + "</min>"
	          + "<colname>" + colcfg[i].val + "</colname>"
	          + "<aliasname>" + colcfg[i].aliasname + "</aliasname>"
	          + "<vis>" + colcfg[i].vis + "</vis>"
	          + "</item>";
	   
	}
	GlcolInfo += "</items>";
    listGl.create("GlCtr"); 
    listGl.onRowRClick = onRowRClick_Gl;
     var serverUrl = "_method=GetGlInfo"
                                   + "&GrBM=" + escape(bm)
                                   + "&GrType="+ m_GrType
                                   + "&colinfo="+ escape(GlcolInfo);
                                  
     var vXml = top.CtnTrans.getText("/main.ashx?", "post", serverUrl)
     
     if (!CtnError.validate(vXml))
     {
        CtnError.show();
        return;
     }
     listGl.reset();
     listGl.insertXml(vXml, 1);
     
     listGl.show();  
}

function onRowRClick_Gl(evt,rowno)
{
    var GldID = listGl.getCell(rowno,0).text
    mc1 = new CtnMenuCtrl("mc1");
    
   
    mc1.addEvent("查看光路", "GetGrByGl('"+GldID+"')");
    
    mc1.show(evt);
}

function GetGrByGl(id)
{
    tc.setActive(0);
    listGr.create("GrListCtr");
    listGr.pagesize = 20;
    listGr.onRowRClick = onRowRClick_Gr;
    listGr.onCheck     = onCheck_Gr;
    listGr.onCheckToggle = onCheckToggle_Gr;
    
//    CtnTrans.Ajax("/main.ashx?_method=GetGrByGld", "post",serverUrl,GrInfoXml,null,{loading:true,loadingText:"正在查询光路，请稍等..."})
    listGr.onGoPage = function (pageno)
    {
        var serverUrl = "_method=GetGrByGld"
                         + "&GldId=" + encodeURIComponent(id)
                         + "&tickettype=" + encodeURIComponent(m_tickettype)
                         + "&grtype=" + encodeURIComponent(m_GrType) 
                         + "&colinfo=" + encodeURIComponent(colinfoxml)
                         + "&init=0&pageno=" + pageno + "&size=" + listGr.pagesize;
                          
        CtnTrans.Ajax("/main.ashx?_method=GetGrByGld", "post",serverUrl,GrInfoXml,null,{loading:true,loadingText:"正在查询光路，请稍等..."})
    }  
    var serverUrl = "_method=GetGrByGld"
                     + "&GldId=" + encodeURIComponent(id)
                     + "&tickettype=" + encodeURIComponent(m_tickettype)
                     + "&grtype=" + encodeURIComponent(m_GrType) 
                     + "&colinfo=" + encodeURIComponent(colinfoxml)
                     + "&init=1&pageno=" + 1 + "&size=" + listGr.pagesize;
                     
    CtnTrans.Ajax("/main.ashx?_method=GetGrByGld", "post",serverUrl,GrInfoXml,null,{loading:true,loadingText:"正在查询光路，请稍等..."}) 
}

function GrInfoXml(res)
{
    var vXml = res.responseText;
    if (!CtnError.validate(vXml))
    {
        CtnError.show();
        return;
    }
    dispgr(vXml) 
}

//调整光路

function ModifyGr(bm)
{
    var param = {};
    param.DzType = 1;
    param.SerialNo = "";
    param.IsSF = 0;
    param.GluBm = bm;
    param.GrPzType = 1;
    param.GrType = m_GrType;
    
    
    top.ExecuteATool(top.m_vt.GQGRGL_GRCFG,[param])
}

//拆除光路

function DelGr(bm)
{
     if(confirm("请确认，是否要删除"))
     { 
         var serverUrl = "_method=deletegr" + "&bm=" + escape(bm) + "&type=" + m_GrType;
                                      
         var vXml = top.CtnTrans.getText("/main.ashx?", "post", serverUrl)
         
         if (!CtnError.validate(vXml))
         {
            CtnError.show();
            return;
         }
         alert("光路拆除成功!"); 
     }
}
function GetDspCol()
{
    var colcfg = GetQueCfg(1006);
    var colval = ""
    var visval = ""
    for(var i = 0; i < colcfg.length; i++)
    {
        visval += colcfg[i].vis != null ? colcfg[i].vis : 1;
        colval += colcfg[i].aliasname 
        if(i + 1 < colcfg.length)
        {
            visval += "|";
            colval += "|";
        }
    }
    colvalue = visval + "@" + colval
    return colvalue;
}

function GenerateExcel(type)
{
    var strGrBm = GetGrBm();
    switch(type)
    {
        case 0:
            CtnTrans.Ajax("/main.ashx?_method=GetXtList", "post","strGrBm="+strGrBm+"&GrType=0",XtInfoEecel,null,{loading:true,loadingText:"正在导出信息，请稍等..."})
            break;
        case 1:
            CtnTrans.Ajax("/main.ashx?_method=GetDlList", "post","strGrBm="+strGrBm+"&GrType=0",DlInfoEecel,null,{loading:true,loadingText:"正在导出信息，请稍等..."})
            break;
        case 2:
            CtnTrans.Ajax("/main.ashx?_method=GetLyList", "post","strGrBm="+strGrBm+"&GrType=0",GrLyEecel,null,{loading:true,loadingText:"正在导出信息，请稍等..."})
            break;
        case 3:
            var colvalue = GetDspCol();
            var tabname = "GrLy.xls"
            var Url = "../GqGr/Excel.aspx?FileName="+escape(tabname)+"&FileType=15"+"&ColVal="+colvalue;
            window.open(Url,"","");
            break;
        default:
            break;
    }
//    var tabname = "GrLy.xls"
//    var Url = "../GqGr/Excel.aspx?FileName="+escape(tabname)+"&FileType="+10;
//    window.open(Url,"","");
}
function GetGrBm()
{
    var strGrBm = ""
    for(var i = 0; i < rownoArr.length; i++)
    {
        strGrBm += listGr.getCell(rownoArr[i], 0).val
        if(i + 1 < rownoArr.length)
        {
            strGrBm += "|"
        }
    }
    return strGrBm;
}

function GrLyEecel(res)
{
    var vData = res.responseText;
    if(vData != "Success")
    {
        CtnDlg.msg(vData);
        return; 
    }
    else
    {   
        var tabname = "GrLy.xls"
        var Url = "../GqGr/Excel.aspx?FileName="+escape(tabname)+"&FileType="+14;
        window.open(Url,"","");
    }
}

function XtInfoEecel(res)
{
    var vData = res.responseText;
    if(vData != "Success")
    {
        CtnDlg.msg(vData);
        return; 
    }
    else
    {   
        var tabname = "XtInfo.xls"
        var Url = "../GqGr/Excel.aspx?FileName="+escape(tabname)+"&FileType="+13;
        window.open(Url,"","");
    }
}

function DlInfoEecel(res)
{
    var vData = res.responseText;
    if(vData != "Success")
    {
        CtnDlg.msg(vData);
        return; 
    }
    else
    {   
        var tabname = "DlInfo.xls"
        var Url = "../GqGr/Excel.aspx?FileName="+escape(tabname)+"&FileType="+11;
        window.open(Url,"","");
    }
}